home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 052a / raylat10.zip / LAT2RAYL.C < prev    next >
Text File  |  1993-03-26  |  3KB  |  104 lines

  1. #include <stdio.h>
  2.  
  3. #define VERSION 1.00
  4.  
  5. FILE *lathefile1, *lathefile2;
  6.  
  7. void main(argc,argv)
  8.     int argc;
  9.     char *argv[];
  10.     {
  11.     char filename1[30], filename2[30];
  12.     unsigned char byte;
  13.     int word, x, y;
  14.     int count;
  15.     int io_count = 0;
  16.  
  17.     fprintf(stderr,"Lat2RayL v%2.2f (c) 1993 Koehler\n\n",VERSION);
  18.     if(argc < 2)   /* Missing the input file name argument - bitch and die */
  19.        {
  20.        puts("     Usage: lat2rayl <infile>\n");
  21.        exit(1);
  22.        }
  23.     strcpy(filename1, argv[1]);
  24.     if (strchr(filename1, '.') != NULL)
  25.     {
  26.     printf("File cannot have an extension\n");
  27.     exit(2);
  28.     }
  29.     strcpy(filename2, filename1);
  30.     strcat(filename1, ".lat");
  31.     strcat(filename2, ".dat");
  32.     lathefile1=fopen(filename1,"rb");
  33.     if (lathefile1 == NULL)
  34.     {
  35.     printf("Error opening '%s'\n", filename1);
  36.     exit(3);
  37.     }
  38.     lathefile2=fopen(filename2,"w");
  39.     if (lathefile2 == NULL)
  40.     {
  41.     printf("Error opening '%s'\n", filename2);
  42.     fclose(lathefile1);
  43.     exit(3);
  44.     }
  45.     if (fseek(lathefile1, 48, SEEK_SET))
  46.     {
  47.     printf("Error seeking '%s'\n", filename1);
  48.     fclose(lathefile1);
  49.     fclose(lathefile2);
  50.     exit(4);
  51.     }
  52.     io_count = fread(&byte, 1, 1, lathefile1);
  53.     count = byte;
  54.     io_count += fread(&byte, 1, 1, lathefile1);
  55.     if (io_count != 2)
  56.     {
  57.     printf("Error reading '%s'\n", filename1);
  58.     fclose(lathefile1);
  59.     fclose(lathefile2);
  60.     exit(5);
  61.     }
  62.     count += byte * 256;
  63.     printf("%s contains %d points\n", filename1, count);
  64.     io_count += fread(&byte, 1, 1, lathefile1);
  65.     x = byte;
  66.     io_count += fread(&byte, 1, 1, lathefile1);
  67.     x += byte * 256;
  68.     io_count += fread(&byte, 1, 1, lathefile1);
  69.     y = byte;
  70.     io_count += fread(&byte, 1, 1, lathefile1);
  71.     y += byte * 256;
  72.     if (io_count != 6)
  73.     {
  74.     printf("Error reading '%s'\n", filename1);
  75.     fclose(lathefile1);
  76.     fclose(lathefile2);
  77.     exit(5);
  78.     }
  79.     fprintf(lathefile2, "%d %d %d\n", x, y, 0);
  80.     for (word=1; word < count; word++)
  81.     {
  82.     io_count = 0;
  83.     io_count += fread(&byte, 1, 1, lathefile1);
  84.     x = byte;
  85.     io_count += fread(&byte, 1, 1, lathefile1);
  86.     x += byte * 256;
  87.     io_count += fread(&byte, 1, 1, lathefile1);
  88.     y = byte;
  89.     io_count += fread(&byte, 1, 1, lathefile1);
  90.     y += byte * 256;
  91.     if (io_count != 4)
  92.         {
  93.         printf("Error reading '%s'\n", filename1);
  94.         fclose(lathefile1);
  95.         fclose(lathefile2);
  96.         exit(5);
  97.         }
  98.     fprintf(lathefile2, "%d %d %d\n", x, y, -1);
  99.     }
  100.     fprintf(lathefile2, "%d %d %d\n", -1, -1, -1);
  101.     fclose(lathefile2);
  102.     fclose(lathefile1);
  103.     }
  104.